/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */
package agent.Metrics.Surprise;

import java.util.ArrayList;

import poi.Surprise.SurpriseDaysOff;
import poi.Surprise.SurprisePrice;
import poi.Surprise.SurpriseSchedule;

/**
 * This class is used to store the Agent's past knowledge from the database
 * 
 * @author Hernani Costa
 * @version 0.1 date: 3/12/2012
 */
public class PastSurpriseValues {
	private ArrayList<SurpriseDaysOff> listSurpriseDayOff;
	private ArrayList<SurprisePrice> listSurprisePrice;
	private ArrayList<SurpriseSchedule> listSurpriseSchedule;
	private SurpriseDaysOff surpriseDayOff;
	private SurprisePrice surprisePrice;
	private SurpriseSchedule surpriseSchedule;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 */
	public PastSurpriseValues() {
		listSurpriseDayOff = new ArrayList<SurpriseDaysOff>();
		listSurprisePrice = new ArrayList<SurprisePrice>();
		listSurpriseSchedule = new ArrayList<SurpriseSchedule>();

	}

	/**
	 * ------------------------------------------------------------------------
	 * This class stores the surprise values from the database
	 * ------------------------------------------------------------------------
	 * 
	 * @param surpriseDayOff
	 *            - surprise value for the parameter DayOff
	 * @param surprisePrice
	 *            - surprise value for the parameter Price
	 * @param surpriseSchedule
	 *            - surprise value for the parameter Schedule
	 */
	public void addSurprise(SurpriseDaysOff surpriseDayOff,
			SurprisePrice surprisePrice, SurpriseSchedule surpriseSchedule) {
		listSurpriseDayOff.add(surpriseDayOff);
		listSurprisePrice.add(surprisePrice);
		listSurpriseSchedule.add(surpriseSchedule);
		surpriseDayOff = getValuesForDaysOff();
		surprisePrice = getValuesForPrice();
		surpriseSchedule = getValuesForSchedule();
	}

	private SurpriseDaysOff getValuesForDaysOff() {
		surpriseDayOff = null;
		int divisor = listSurpriseDayOff.size();
		double monday = 0.0, tuesday = 0.0, wednesday = 0.0, thusday = 0.0, friday = 0.0, saturday = 0.0, sunday = 0.0;

		for (SurpriseDaysOff temp : listSurpriseDayOff) {
			monday += temp.getMonday();
			tuesday += temp.getTuesday();
			wednesday += temp.getWednesday();
			thusday += temp.getThursday();
			friday += temp.getFriday();
			saturday += temp.getSaturday();
			sunday += temp.getSunday();
		}
		surpriseDayOff = new SurpriseDaysOff(sunday / divisor,
				monday / divisor, tuesday / divisor, wednesday / divisor,
				thusday / divisor, friday / divisor, saturday / divisor);

		return surpriseDayOff;
	}

	private SurprisePrice getValuesForPrice() {
		surprisePrice = null;
		int divisor = listSurprisePrice.size();
		double cheap = 0.0, average = 0.0, expensive = 0.0;

		for (SurprisePrice temp : listSurprisePrice) {
			cheap += temp.getCheap();
			average += temp.getAverage();
			expensive += temp.getExpensive();
		}
		surprisePrice = new SurprisePrice(cheap / divisor, average / divisor,
				expensive / divisor);

		return surprisePrice;
	}

	private SurpriseSchedule getValuesForSchedule() {
		surpriseSchedule = null;
		int divisor = listSurpriseSchedule.size();
		double morning = 0.0, afternoon = 0.0, night = 0.0;

		for (SurpriseSchedule temp : listSurpriseSchedule) {
			morning += temp.getMorning();
			afternoon += temp.getAfternoon();
			night += temp.getNight();
		}
		surpriseSchedule = new SurpriseSchedule(morning / divisor, afternoon
				/ divisor, night / divisor);

		return surpriseSchedule;
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------
	public SurpriseDaysOff getSurpriseDayOff() {
		return surpriseDayOff;
	}

	public SurprisePrice getSurprisePrice() {
		return surprisePrice;
	}

	public SurpriseSchedule getSurpriseSchedule() {
		return surpriseSchedule;
	}

}
